package cn.iocoder.yudao.module.member.controller.admin.order;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.member.controller.admin.order.vo.CertificateOrderCountTypeVo;
import cn.iocoder.yudao.module.member.controller.admin.order.vo.CertificateOrderCountUserVo;
import cn.iocoder.yudao.module.member.controller.admin.order.vo.CertificateOrderCountVo;
import cn.iocoder.yudao.module.member.service.order.CertificateOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "用户 App - 证书管理")
@RestController
@RequestMapping("/member/certificate")
@Validated
public class AdminCertificateOrderController {

    @Resource
    private CertificateOrderService certificateOrderService;

    @PostMapping("/queryCount")
    @Operation(summary = "获取订单统计信息")
    @PreAuthorize("@ss.hasPermission('certificate:queryCount')")
    public CommonResult<CertificateOrderCountVo> queryCount() {
        // 执行分页查询
        CertificateOrderCountVo   vo = certificateOrderService.queryCount();

        return success(vo);
    }

    @PostMapping("/queryCountByType")
    @Operation(summary = "证书运营统计")
    @PreAuthorize("@ss.hasPermission('certificate:queryCountByType')")
    public CommonResult<CertificateOrderCountTypeVo> queryCountByType() {
        // 执行分页查询
        CertificateOrderCountTypeVo vo = certificateOrderService.queryCountByType();
        return success(vo);
    }

    @GetMapping("/queryCountByUser")
    @Operation(summary = "客户排行统计")
    @Parameter(name = "flag", description = "yesterday-查询昨天  all-查询所有 today-今天", example = "all")
    @PreAuthorize("@ss.hasPermission('certificate:queryCountByUser')")
    public CommonResult<CertificateOrderCountUserVo> queryCountByUser(@RequestParam("flag") String flag) {
        // 执行分页查询
        CertificateOrderCountUserVo vo = certificateOrderService.CertificateOrderCountUserVo(flag);
        return success(vo);
    }

    @GetMapping("/downloadCertificate")
    @Operation(summary = "下载证书和描述文件")
    @PreAuthorize("@ss.hasPermission('certificate:downloadCertificate')")
    public void downloadCertificate(HttpServletRequest request, HttpServletResponse response) throws Exception {
        certificateOrderService.downloadCertificate(request, response);
    }

    @GetMapping("/downloadCertificateCheck")
    @Operation(summary = "校验")
    @PreAuthorize("@ss.hasPermission('certificate:downloadCertificateCheck')")
    public void downloadCertificateCheck(HttpServletRequest request, HttpServletResponse response) throws Exception {
        certificateOrderService.downloadCertificateCheck(request, response);
    }

}
